var xlsx = require('node-xlsx');
var fs = require('fs');

async function exportExcel(params) {
    var excelData = [];
    for (const key in params.tables) {
        var addInfo = {};
        addInfo.name = params.tables[key]['sheet'];
        addInfo.data = params.tables[key]['data'];
        excelData.push(addInfo);
    }
    var buffer = xlsx.build(excelData);
    try {
        await fs.writeFileSync(__dirname + `/../../public/files/${params.title}.xlsx`, buffer);
        return true;
    } catch (error) {
        return false;
    }
}
module.exports = {
    exportExcel
}